package com.baitiaojun.repeatsubmit.config;

import com.baitiaojun.common.constants.WebInterceptorOrderEnum;
import com.baitiaojun.repeatsubmit.core.interceptor.RepeatSubmitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration
public class SubmitRepeatConfig implements WebMvcConfigurer {

    @Autowired
    @Qualifier("repeatSubmitDefaultRule")
    private RepeatSubmitInterceptor repeatSubmitInterceptor;

    /**
     * 添加防重复提交拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(repeatSubmitInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/webjars/**","/swagger-ui.html",
                        "/swagger-resources/**", "/*/api-docs", "/druid/**",
                        "/**/publicKey", "/**/captchaImage")
                .order(WebInterceptorOrderEnum.SUBMIT_REPEAT_INTERCEPTOR);
    }
}
